package net.csdn.business.common.domain.issue.event;

import lombok.*;
import lombok.experimental.SuperBuilder;
import net.csdn.business.common.domain.issue.IssueExt;
import net.csdn.business.common.enums.IssueEnum;
import net.csdn.business.common.enums.UserTypeEnum;
import net.csdn.business.common.utils.BusinessUtil;

import java.util.List;

/**
 * @author likun
 * @date 2022/11/17 14:42
 */
@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
public class UpdateStatusEventDto extends BaseEventDto {
    private String content;

    /**
     * 评论@username列表
     */
    private List<String> ats;

    /**
     * {@link net.csdn.business.common.enums.IssueEnum.StatusEnum}
     */
    private Integer status;

    /**
     * {@link net.csdn.business.common.enums.IssueEnum.StatusReasonEnum}
     */
    private Integer statusReason;

    /**
     * 以下通过仓库操作需要的信息
     *
     * @lik0914 lik0914 closed this as completed in #5 3 hours ago
     **/

    private Long mergeRequestIid;

    private String pathWithNamespace;

    private String nameWithNamespace;


    public UpdateStatusEventDto(String id, String actionUid, Long projectId, Integer serialNumber, String title, String content, Integer status) {
        super(id, actionUid, UserTypeEnum.USER.getType(), projectId, serialNumber, title);
        this.content = BusinessUtil.notifyContentSubstring(content);
        this.status = status;
    }

    public UpdateStatusEventDto(String id, String actionUid, Integer userType, Long projectId, Integer serialNumber, String title, String content, Integer status, IssueExt ext,List<String> ats) {
        super(id, actionUid, userType, projectId, serialNumber, title);
        this.content = BusinessUtil.notifyContentSubstring(content);
        this.status = status;
        this.ats=ats;
        super.setExt(ext);
    }

    public static UpdateStatusEventDto buildChangeEvent(String id, Long projectId, String actionUid, Integer status, Integer statusReason) {
        return UpdateStatusEventDto.builder()
                .id(id).projectId(projectId)
                .actionUid(actionUid).status(status).statusReason(statusReason)
                .build();
    }

    public static UpdateStatusEventDto buildChangeEvent(String id, Long projectId, String actionUid, Integer actionUserType, Integer status, Integer statusReason, IssueExt ext) {
        UpdateStatusEventDto dto = buildChangeEvent(id, projectId, actionUid, status, statusReason);
        dto.setActionUserType(actionUserType);
        dto.setExt(ext);
        return dto;
    }

    public static UpdateStatusEventDto buildMrCloseChangeEvent(String id, Long projectId, String actionUid, Long mergeRequestIid, String pathWithNamespace, String nameWithNamespace) {
        return UpdateStatusEventDto.builder()
                .id(id).projectId(projectId)
                .actionUid(actionUid).status(IssueEnum.StatusEnum.CLOSE.getCode()).statusReason(IssueEnum.StatusReasonEnum.MR_CLOSE.getCode())
                .mergeRequestIid(mergeRequestIid).pathWithNamespace(pathWithNamespace).nameWithNamespace(nameWithNamespace)
                .build();
    }
}